<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

</head>

<body class="ms-theme-blue">

  <%@ include file="/WEB-INF/include/header.jsp"%>
  <%@ include file="/WEB-INF/include/submenu.jsp"%>

  <div class="container-fluid ms-container has-ms-sidemenu">

    <ol class="ms-breadcrumb breadcrumb">
      <li class="active">牵引车信息管理</li>
    </ol>
    
    <div class="ms-content-layout">

      <ul class="nav nav-tabs ms-nav-tabs" role="tablist">
        <li role="presentation" class="${status.editing ? 'active' : ''}"><a href="${ctx.host}/tractors?status=EDITING">编辑中</a></li>
        <li role="presentation" class="${status.auditing ? 'active' : ''}"><a href="${ctx.host}/tractors?status=AUDITING">待审核</a></li>
        <li role="presentation" class="${status.rejected ? 'active' : ''}"><a href="${ctx.host}/tractors?status=REJECTED">已驳回</a></li>
        <li role="presentation" class="${status.qualified ? 'active' : ''}"><a href="${ctx.host}/tractors?status=QUALIFIED">合格</a></li>
        <li role="presentation" class="${status.modified ? 'active' : ''}"><a href="${ctx.host}/tractors?status=MODIFIED">变更申报</a></li>
      </ul>

      <div class="ms-operation-bar no-margin no-bottom-border clearfix">

        <div class="ms-operation-group">
          
          <div class="pull-left">
            <c:if test="${status.editing or status.rejected}">
              <a href="${ctx.host}/tractors/batch-audit" data-target="#batch-audit" data-toggle="modal" class="btn ms-btn ms-btn-blue batch-audit"> 
                <i class="glyphicon"></i>&nbsp;&nbsp;批量递交审核
              </a>
            </c:if>
          </div>

          <div class="pull-right">
            <a href="${ctx.host}/tractors/search?status=${status}" data-target="#search" data-toggle="modal" class="btn ms-btn ms-btn-blue"> 
              <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
            </a>

            <c:if test="${status.editing and supplier and !vam}">
              <a href="${ctx.host}/tractors/create" data-target="#create" class="btn ms-btn ms-btn-blue"> 
                <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;新增车辆
              </a>
              <a href="${ctx.host}/tractors/upload" data-target="#upload" data-toggle="modal" class="btn ms-btn ms-btn-blue"> 
                <i class="glyphicon glyphicon-upload"></i>&nbsp;&nbsp;批量导入
              </a>
              <a href="${ctx.resource}/template/vehicle/tractor-import-template.xls" target="_blank" download="安吉物流供应商运输工具-牵引车导入模板.xls" class="btn ms-btn ms-btn-blue"> 
                <i class="glyphicon glyphicon-download"></i>&nbsp;&nbsp;批量导入模板下载
              </a>
            </c:if>
          </div>
        </div>
      </div>

      <table class="table table-hover ms-table">
        <thead>
          <tr>
            <c:if test="${status.editing or status.rejected}">
              <th><input type="checkbox" id="checkAll" name="checkAll" /></th>
            </c:if>
            <th>序号</th>
            <th>中文车牌号</th>
            <th>英文车牌号</th>
            <th>运输工具类型</th>
            <th>装载量</th>
            <th>是否同步TMS</th>
            <th>所属供方</th>
            <c:if test="${status.rejected}">
              <th>驳回理由</th>
            </c:if>
            <c:if test="${status.qualified}">
              <th>申报时间</th>
              <th>是否绑定挂车</th>
            </c:if>
            <th class="text-center">操作</th>
          </tr>
        </thead>

        <tbody>
          <c:forEach var="tractor" items="${tractors}" varStatus="item">
            <tr>
              <c:if test="${status.editing or status.rejected}">
                <td><input type="checkbox" name="id" value="${tractor.id}"/></td>
              </c:if>
              <td>${item.count}</td>
              <td>${tractor.brandCNCode}</td>
              <td>${tractor.brandENCode}</td>
              <td>${tractor.transMean.description}</td>
              <td>${tractor.trainload}</td>
              <td>${tractor.synchronize ? '是' : '否'}</td>
              <td>${tractor.supplier.name}</td>
              <c:if test="${status.rejected}">
                <td>${tractor.rejectReason}</td>
              </c:if>
              <c:if test="${status.qualified}">
                <td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${tractor.declareTime}"/></td>
                <td>${tractor.bind ? '是' : '否'}</td>
              </c:if>
              <td class="text-center">
                
                <a href="${ctx.host}/tractors/${tractor.id}?tractorMenuType=self">详情</a>&nbsp;&nbsp;
                
                <c:if test="${(not vam) and (not tractor.vam)}">
                  <c:choose>
                    <c:when test="${status.editing}">
                      <a href="${ctx.host}/tractors/${tractor.id}/audit" data-target="#audit" data-toggle="modal">递交审核</a>&nbsp;&nbsp;
                      <a href="${ctx.host}/tractors/${tractor.id}/delete" data-target="#delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
                      <a href="${ctx.host}/tractors/${tractor.id}/transfer" data-target="#transfer" data-toggle="modal">转籍</a>  
                    </c:when>
                    
                    <c:when test="${status.auditing}">
                      <a href="${ctx.host}/tractors/${tractor.id}/delete" data-target="#delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
                    </c:when>
                    
                    <c:when test="${status.rejected}">
                      <c:choose>
                        <c:when test="${tractor.declareStatus.unsync}">
                          <a href="${ctx.host}/tractors/${tractor.id}/audit" data-target="#audit" data-toggle="modal">递交审核</a>&nbsp;&nbsp;
                        </c:when>
                        <c:otherwise>
                          <a href="${ctx.host}/tractors/${tractor.id}/change">变更申报</a>&nbsp;&nbsp;
                        </c:otherwise>
                      </c:choose>
                      <a href="${ctx.host}/tractors/${tractor.id}/delete" data-target="#delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
                      <a href="${ctx.host}/tractors/${tractor.id}/transfer" data-target="#transfer" data-toggle="modal">转籍</a>
                    </c:when>
                               
                    <c:when test="${status.qualified}">
                      <a href="${ctx.host}/tractors/${tractor.id}/change">变更申报</a>&nbsp;&nbsp;
                      <a href="${ctx.host}/tractors/${tractor.id}/transfer" data-target="#transfer" data-toggle="modal">转籍</a>&nbsp;&nbsp;
                      <c:choose>
                        <c:when test="${tractor.synchronize}">
                          <a href="${ctx.host}/tractors/${tractor.id}/out" data-target="#out" data-toggle="modal">转出</a>&nbsp;&nbsp;
                        </c:when>
                        <c:otherwise>
                          <a href="${ctx.host}/tractors/${tractor.id}/delete" data-target="#delete" data-toggle="modal">删除</a>&nbsp;&nbsp;
                        </c:otherwise>
                      </c:choose>
                    </c:when>
                    
                  </c:choose>
                </c:if>
                
              </td>
            </tr>
          </c:forEach>
        </tbody>

        <tfoot>
          <tr>
            <td colspan="10" class="no-vertical-padding">
              <div class="pull-left">
                <jsp:include page="/WEB-INF/include/page.jsp">
                  <jsp:param name="url" value="tractors" />
                  <jsp:param name="queryString" value="${queryString}" />
                </jsp:include>
              </div>
            </td>
          </tr>
        </tfoot>
      </table>
    </div>

  </div>
  
  <c:if test="${not empty tractorUploadResults}">
    <div class="modal fade" id="tractor-upload-result" tabindex="-1" role="dialog">
      <div class="modal-dialog ms-modal-dialog" style="width: 600px;" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
              <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title">上传结果</h4>
          </div>

          <div class="modal-body">
            <table class="table table-hover ms-table">
              <thead>
                <tr>
                  <th>Excel行号</th>
                  <th>错误信息</th>
                  <th>车辆所属供方</th>
                  <th>牵引车中文车牌号</th>
                </tr>
              </thead>

              <tbody>
                <c:forEach var="result" items="${tractorUploadResults}">
                  <tr>
                    <td>${result.rowNum}</td>
                    <td>${result.message}</td>
                    <td>${result.supplier}</td>
                    <td>${result.vehicle}</td>
                  </tr>
                </c:forEach>
              </tbody>
            </table>
          </div>

          <div class="modal-footer">
            <button type="button" class="btn ms-btn btn-primary" data-dismiss="modal">确定</button>
          </div>
        </div>
      </div>
    </div>
  </c:if>

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource type="script" root="${ctx.resource}/build" src="js/page/supplier/management/tractor/tractor-info-list.js" />
  <script type="text/javascript">
    require(['page/supplier/management/tractor/tractor-info-list'], function (page) {
      page.init()
    })
  </script>

</body>
</html>